#!/bin/sh
################################################################################
# irtrans
################################################################################
. /etc/rc.d/functions

start() {
    /usr/bin/logger -s -t minimyth -p "local0.info" "[init.d/irtrans] Starting..."

    if [ "x${MM_LCDPROC_DRIVER}" = "xirtrans" ] || \
       [ "x${MM_LIRC_DRIVER}"    = "xirtrans" ] ; then
        if [ -n "${MM_LCDPROC_DEVICE}" ] ; then
            # mm_message_output info "starting irtrans server ..."
            # Use IRTrans server's LIRC support if
            # either the LIRC driver is 'irtrans',
            # or there is no other LIRC device.
            if [ "x${MM_LIRC_DRIVER}" = "xirtrans" ] || \
               [ -z "${MM_LIRC_DEVICE_LIST}" ] ; then
                /usr/sbin/irserver \
                    -logfile /var/log/irserver \
                    -pidfile /var/run/irserver.pid \
                    -daemon "${MM_LCDPROC_DEVICE}"
            else
                /usr/sbin/irserver \
                    -no_lirc \
                    -logfile /var/log/irserver \
                    -pidfile /var/run/irserver.pid \
                    -daemon "${MM_LCDPROC_DEVICE}"
            fi
        fi
    fi

    /usr/bin/logger -s -t minimyth -p "local0.info" "[init.d/irtrans] Started with return code=0..."

    return 0
}

stop() {

    if [ -n "`/bin/pidof irserver`" ] ; then
        mm_message_output info "stopping irtrans server ..."
        if [ -e /usr/sbin/irclient ] ; then
            /usr/sbin/irclient localhost -shutdown
        else
            /usr/bin/killall irserver
        fi
    fi

    return 0
}

case $1 in
    start) start ;;
    stop)  stop  ;;
esac

exit 0
